﻿using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Advertise", "advId", "Torch.WL.ConnectionString")]
    public class Tb_Advertise : Info
    {
        #region SQL column name consts
        public const string SQLCOL_ADVID = "advId";
        public const string SQLCOL_ADV_TITLE = "adv_title";
        public const string SQLCOL_ADV_IMG = "adv_img";
        public const string SQLCOL_ADV_ISCURRENT = "adv_isCurrent";
        public const string SQLCOL_CREATETIME = "createTime";
        #endregion


        #region Contructors
        /// <summary>
        /// Construct empty entity
        /// </summary>
        public Tb_Advertise() { }

        /// <summary>
        /// Construct entity by primary key, other fields will be assigned by 
        /// "Load" method.
        /// </summary>
        public Tb_Advertise(int advId)
        {
            this.advId = advId;
        }
        #endregion

        public override void Init(DataRow row)
        {
            advId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ADVID]);
            adv_title = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ADV_TITLE]);
            adv_img = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ADV_IMG]);
            adv_isCurrent = (byte)ObjectType.ByteTypeHelper.Read(row[SQLCOL_ADV_ISCURRENT]);
            createTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
        }

        #region Properties
        #region Property <int> advId
        [Property("advId", 4, SqlDbType.Int, true, true)]
        public int advId
        {
            get { return _advId; }
            set { _advId = value; }
        }
        private int _advId = int.MinValue;
        #endregion

        #region Property <string> adv_title
        [Property("adv_title", 200, SqlDbType.VarChar, false, false)]
        public string adv_title
        {
            get { return _adv_title; }
            set { _adv_title = value; }
        }
        private string _adv_title = null;
        #endregion

        #region Property <string> adv_img
        [Property("adv_img", 100, SqlDbType.VarChar, false, false)]
        public string adv_img
        {
            get { return _adv_img; }
            set { _adv_img = value; }
        }
        private string _adv_img = null;
        #endregion

        #region Property <byte> adv_isCurrent
        [Property("adv_isCurrent", 1, SqlDbType.TinyInt, false, false)]
        public byte adv_isCurrent
        {
            get { return _adv_isCurrent; }
            set { _adv_isCurrent = value; }
        }
        private byte _adv_isCurrent = byte.MinValue;
        #endregion

        #region Property <DateTime> createTime
        [Property("createTime", 16, SqlDbType.DateTime, false, false)]
        public DateTime createTime
        {
            get { return _createTime; }
            set { _createTime = value; }
        }
        private DateTime _createTime = DateTime.MinValue;
        #endregion
        #endregion


        public bool LoadByIdentity(int advId)
        {
            return DataAccess.SelectByIdentity(this, Convert.ToInt64(advId));
        }


        public bool DeleteByIdentity()
        {
            return DataAccess.DeleteByIdentity(this);
        }
    }
}
